package joomz;

import javax.script.Bindings;

/**
 * Action actor
 */
public class Actor
    extends Action
    implements Enumerated.Member
{
    public final static Enumerated<Actor> Set = new Enumerated<Actor>();

    public final static Actor Dereference(String id){
        Actor re = Set.forName(id);
        if (null != re)
            return re;
        else {
            re = new Actor();
            re.setId(id);
            Set.register(re);
            return re;
        }
    }


    public Actor(){
        super();
    }

    public void init(Bindings bindings){
        Set.register(this);
        Event event = this.getEvent();
        if (null != event)
            event.init(bindings);
    }
    public boolean matches(Action pattern){

        if (null != pattern.actor && this.equals(pattern.actor)){

            if (null != this.dir){
                if (null == pattern.dir || (!this.dir.equals(pattern.dir)))
                    return false;
            }
            else if (null != this.item){
                if (null == pattern.item ||(!this.item.equals(pattern.item)))
                    return false;
            }
            else if (null != this.object){
                if (null == pattern.object ||(!this.object.equals(pattern.object)))
                    return false;
            }
            return true;
        }
        return false;
    }

    public boolean isValid(){
        return true;
    }
    public java.lang.Object invoke(){
        Event event = this.event;
        if (null != event)
            return event.invoke();
        else
            return null;
    }
    public Actor getActor(){
        return this;
    }
    public boolean setActor(Actor actor){
        return false;
    }
    public boolean setActor(String actor){
        return false;
    }
    public boolean hasActor(String actor){
        return (this == Actor.Set.forName(actor));
    }
}
